package com.jml.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jml.pojo.Permission;
import com.jml.pojo.Role;
import com.jml.pojo.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Set;


public interface UserMapper extends BaseMapper<User> {

    /**
     * 根据名字查找用户
     * @param username
     * @return
     */
    @Select("select * from user where name = #{username}")
    public User findUserByName(String username);

    /**
     * 根据名字获取用户所有角色
     * @param username
     * @return
     */
    @Select("select * from  role where rolecode in(select rolecode from userrole where username = #{username})")
    public Set<Role> getUserRoles(String username);

    /**
     * 根据角色查找用户的权限
     * @param roleCode
     * @return
     */
    @Select("select * from permission where permissioncode in (select permissioncode from rolepermission where rolecode = #{roleCode})")
    Set<Permission> getRolePermissions(String roleCode);



    IPage<User> selectPageVo(Page page, @Param("name") String name);
}
